package chixing.day07.inherited;

import java.util.Objects;

public class Product {
    private int proNo;
    private String proName;
    private float proPrice;

    public Product() {
    }
    public Product(int proNo,String proName, float proPrice) {
        this.proNo = proNo;
        this.proName = proName;
        this.proPrice = proPrice;
    }

    public String getProName() {
        return proName;
    }

    public void setProName(String proName) {
        this.proName = proName;
    }

    public float getProPrice() {
        return proPrice;
    }

    public void setProPrice(float proPrice) {
        this.proPrice = proPrice;
    }

    public int getProNo() {
        return proNo;
    }

    public void setProNo(int proNo) {
        this.proNo = proNo;
    }
    //需比较内容属性值
  //  业务中界定 若商品的所有属性值都一样，则认为二者为相同的商品
    public boolean equals(Object obj) {
       if(obj == null)
        return false;
       if(!obj.getClass().getName().equals(this.getClass().getName()))
        return false;
       if(this==obj)
           return true;
       //if 商品名称是否相同，不同则直接返回false
        // else价格是否相同，不同则返回false
        //else商品编号是否相同，不同则返回false
        Product p2 = (Product)obj;
        if(this.proName.equals(p2.proName)&&this.proPrice==p2.proPrice&&this.proNo==p2.proNo)
            return true;
        return false;
    }


//    @Override
//    public boolean equals(Object o) {
//        if (this == o) return true;
//        if (o == null || getClass() != o.getClass()) return false;
//        Product product = (Product) o;
//        return proNo == product.proNo && Float.compare(proPrice, product.proPrice) == 0 && Objects.equals(proName, product.proName);
//    }

    @Override
    public int hashCode() {
        return Objects.hash(proNo, proName, proPrice);
    }

    @Override
    public String toString() {
        return "Product{" +
                "proName='" + proName + '\'' +
                ", proPrice=" + proPrice +
                '}';
    }
}
